import {
	toChildArray as t,
	cloneElement as n,
	createElement as e,
	Component as r
}
from "preact";
function o(t, n) {
	return (o = Object.setPrototypeOf ||
	function(t, n) {
		return t.__proto__ = n,
		t
	})(t, n)
}
var i = {};
function a(t, n) {
	for (var e in n) t[e] = n[e];
	return t
}
function u(t, n, e) {
	var r, o = /(?:\?([^#]*))?(#.*)?$/,
	a = t.match(o),
	u = {};
	if (a && a[1]) for (var c = a[1].split("&"), h = 0; h < c.length; h++) {
		var p = c[h].split("=");
		u[decodeURIComponent(p[0])] = decodeURIComponent(p.slice(1).join("="))
	}
	t = l(t.replace(o, "")),
	n = l(n || "");
	for (var s = Math.max(t.length, n.length), f = 0; f < s; f++) if (n[f] && ":" === n[f].charAt(0)) {
		var d = n[f].replace(/(^:|[+*?]+$)/g, ""),
		g = (n[f].match(/[+*?]+$/) || i)[0] || "",
		v = ~g.indexOf("+"),
		m = ~g.indexOf("*"),
		y = t[f] || "";
		if (!y && !m && (g.indexOf("?") < 0 || v)) {
			r = !1;
			break
		}
		if (u[d] = decodeURIComponent(y), v || m) {
			u[d] = t.slice(f).map(decodeURIComponent).join("/");
			break
		}
	} else if (n[f] !== t[f]) {
		r = !1;
		break
	}
	return (!0 === e.
default || !1 !== r) && u
}
function c(t, n) {
	return t.rank < n.rank ? 1 : t.rank > n.rank ? -1 : t.index - n.index
}
function h(t, n) {
	return t.index = n,
	t.rank = function(t) {
		return t.props.
	default ? 0 : l(t.props.path).map(p).join("")
	} (t),
	t.props
}
function l(t) {
	return t.replace(/(^\/+|\/+$)/g, "").split("/")
}
function p(t) {
	return ":" == t.charAt(0) ? 1 + "*+?".indexOf(t.charAt(t.length - 1)) || 4 : 5
}
var s = null,
f = [],
d = [],
g = {};
function v() {
	var t;
	return "" + ((t = s && s.location ? s.location: s && s.getCurrentLocation ? s.getCurrentLocation() : "undefined" != typeof location ? location: g).pathname || "") + (t.search || "")
}
function m(t, n) {
	return void 0 === n && (n = !1),
	function(t) {
		for (var n = f.length; n--;) if (f[n].canRoute(t)) return ! 0;
		return ! 1
	} (t) &&
	function(t, n) {
		void 0 === n && (n = "push"),
		"replace" == n ? (window.location.hash.replace = t) : (window.location.hash = t)
	} (t, n ? "replace": "push"),
	y(t)
}
function y(t) {
	for (var n = !1,
	e = 0; e < f.length; e++) ! 0 === f[e].routeTo(t) && (n = !0);
	for (var r = d.length; r--;) d[r](t);
	return n
}
function C(t) {
	if (t && t.getAttribute) {
		var n = t.getAttribute("route"),
		e = t.getAttribute("target");
		if (n && n.match(/^\//g) && (!e || e.match(/^_?self$/i))) return m(n)
	}
}
function b(t) {
	if (! (t.ctrlKey || t.metaKey || t.altKey || t.shiftKey)) return C(t.currentTarget || t.target || this),
	U(t)
}
function U(t) {
	return t && (t.stopImmediatePropagation && t.stopImmediatePropagation(), t.stopPropagation && t.stopPropagation(), t.preventDefault()),
	!1
}
function k(t) {
	if (! (t.ctrlKey || t.metaKey || t.altKey || t.shiftKey || 0 !== t.button)) {
		var n = t.target;
		do {
			if ("A" === String(n.nodeName).toUpperCase() && n.getAttribute("route")) {
				if (n.hasAttribute("native")) return;
				if (C(n)) return U(t)
			}
		} while ( n = n . parentNode )
	}
}
var x = !1,
w = function(e) {
	var r, i;
	function l(t) {
		var n;
		return n = e.call(this, t) || this,
		t.history && (s = t.history),
		n.state = {
			url: t.url || v()
		},
		x || ("function" == typeof addEventListener && (s || addEventListener("popstate",
		function() {
			y(v())
		}), addEventListener("click", k)), x = !0),
		n
	}
	i = e,
	(r = l).prototype = Object.create(i.prototype),
	r.prototype.constructor = r,
	o(r, i);
	var p = l.prototype;
	return p.shouldComponentUpdate = function(t) {
		return ! 0 !== t.static || t.url !== this.props.url || t.onChange !== this.props.onChange
	},
	p.canRoute = function(n) {
		var e = t(this.props.children);
		return this.getMatchingChildren(e, n, !1).length > 0
	},
	p.routeTo = function(t) {
		this.setState({
			url: t
		});
		var n = this.canRoute(t);
		return this.updating || this.forceUpdate(),
		n
	},
	p.componentWillMount = function() {
		this.updating = !0
	},
	p.componentDidMount = function() {
		var t = this;
		f.push(this),
		s && (this.unlisten = s.listen(function(n) {
			t.routeTo("" + (n.pathname || "") + (n.search || ""))
		})),
		this.updating = !1
	},
	p.componentWillUnmount = function() {
		"function" == typeof this.unlisten && this.unlisten(),
		f.splice(f.indexOf(this), 1)
	},
	p.componentWillUpdate = function() {
		this.updating = !0
	},
	p.componentDidUpdate = function() {
		this.updating = !1
	},
	p.getMatchingChildren = function(t, e, r) {
		return t.filter(h).sort(c).map(function(t) {
			var o = u(e, t.props.path, t.props);
			if (o) {
				if (!1 !== r) {
					var i = {
						url: e,
						matches: o
					};
					return a(i, o),
					delete i.ref,
					delete i.key,
					n(t, i)
				}
				return t
			}
		}).filter(Boolean)
	},
	p.render = function(n, e) {
		var r = n.onChange,
		o = e.url,
		i = this.getMatchingChildren(t(n.children), o, !0),
		a = i[0] || null,
		u = this.previousUrl;
		return o !== u && (this.previousUrl = o, "function" == typeof r && r({
			router: this,
			url: o,
			previous: u,
			active: i,
			current: a
		})),
		a
	},
	l
} (r),
A = function(t) {
	return e("a", a({
		onClick: b
	},
	t))
},
K = function(t) {
	return e(t.component, t)
},
O = {
	getCurrentHash: function() {
		return url = "undefined" != typeof location ? location: g,
		"" + (url.hash || "") + (url.search || "")
	},
	getCurrentHashPath: function() {
		return url = "undefined" != typeof location ? location: g,
		("" !== url.hash || "undefined" !== url.hash) && url.hash.substring(1),
		"" + (url.hash || "") + (url.search || "")
	}
};
export
default w;
	export {
		O as Info,
		A as Link,
		K as Route,
		w as Router,
		u as exec,
		v as getCurrentUrl,
		m as route,
		d as subscribers
	};
	//# sourceMappingURL=preact-router.es.js.map
	